/**
自开发 -> json to form js工具
生成form最终表单
name:表单name
action:表单提交地址
method:提交方式 get / post
json:需要生成的表单dom集合
*/

/**
 * 可拓展json结构
 */
var dic_list = '';
var tp_id=[];//用于返回特定页面的照片id
function formStart_sub(data){
    dic_list = data.dic;
    pro_list = data.pro_dic;
    var form = createForm({action:data.action,name:data.name,method:data.method});
    //追加表格数据
    form.append($('<div class="weui-cells weui-cells_form"></div>'));
    //检测该子集是否有值
    var default_value = data.value;
    //获取子集结构
    var json = data.json;
    if(default_value==undefined || default_value.length==0){
        //无值状态 加载默认数据
        var length = json.length;
        if(length==0){
            //这里使用weui样式
            alert('没有该子集显示项!');
            history.back(-1);
            return;
        }
        for(var i in json){
             //检测是否是为时间标签
             if(json[i].type=='DATE'){
                //生成时间节点
                var date_html = '<div class="weui-cell weui-cell_vcode"><div class="weui-cell__hd"><label for="" class="weui-label"></label></div><div class="weui-cell__bd" style="height:44px;line-height:44px;"></div></div>';
                var div_obj = $(date_html);
                //生成左侧标题
                div_obj.find('div:eq(0)').find('label').html(json[i].caption);
                //生成右侧时间input表单
                var createTimeValue = {
                    name:json[i].name,
                    value:''
                };
                var time_text = createTime(createTimeValue);
                div_obj.find('div:eq(1)').append(time_text);
                form.find('div:eq(0)').append(div_obj);
            }else if(json[i].dictionaries==''){
                var text_html = '<div class="weui-cell weui-cell_vcode"><div class="weui-cell__hd"><label class="weui-label"></label></div><div class="weui-cell"><div class="weui-cell__bd"></div></div></div>';
                //生成text节点
                var text_obj = $(text_html);
                //生成左侧标题
                text_obj.find('div:eq(0)').find('label').html(json[i].caption);
                //生成右侧文本input表单
                var createTextValue = {
                    name:json[i].name,
                    value:json[i].value,
                    caption:json[i].caption
                };
                var temp_text = createText(createTextValue);
                text_obj.find('div:eq(1)').append(temp_text);
                form.find('div:eq(0)').append(text_obj);
            }else{
                //生成select节点
                var select_html = '<div class="weui-cell weui-cell_vcode"><div class="weui-cell__hd"><label class="weui-label"></label></div><div class="weui-cell__hd"></div>';
                var select_obj = $(select_html);
                //生成左侧标题
                select_obj.find('div:eq(0)').find('label').html(json[i].caption);
                //分析字典 默认值
                var dictionaries = json[i].dictionaries;
                var select_data = {
                    name:json[i].name,
                    dictionaries:dictionaries,
                };
                var select = createSelect(select_data);
                select_obj.find('div:eq(1)').append(select);
                form.find('div:eq(0)').append(select_obj);
            }
        }

        //生成提交按钮 和 返回按钮
        var operation_div = $('<div class="operation_div"></div>');
        if(is_dealt==1){
			var submit = $('<input type="button" class="weui-btn weui-btn_primary" value="已在审批中">');
        }else{
        	var submit = $('<input type="submit" class="weui-btn weui-btn_primary" value="新增">');
        }
        var callback = $('<input type="button" class="weui-btn weui-btn_disabled weui-btn_default callback_button" value="取消操作">');
        operation_div.append(submit);
        operation_div.append(callback);
        //添加表单隐藏域信息
        form.append($('<input type="hidden" name="table_name" value="'+data.name+'"/>'));
        //标记该子集是否有值 1 有 0 没有
        form.append($('<input type="hidden" name="has_value" value="0"/>'));
        form.find('div:eq(0)').append(operation_div);
        //最终生成dom节点数据
        $('body').append(form);
    }else{
        //存在数据情况处理
        //检测是否有数据
        if(default_value.length==0){
            location.reload();
            return;
        }

        //统计总数
        var total = 0;
        var div1 = $('<div class="swiper-container"></div>');
        var div2 = $('<div class="swiper-wrapper"></div>');

        //有值状态
        for(var j=0 in default_value){
            total++;
            var temp = $('<div class="swiper-slide"></div>');
            var form = createForm({action:data.action,name:data.name,method:data.method});
            //追加表格数据
            form.append($('<div class="weui-cells weui-cells_form"></div>'));
            var json = default_value[j].info;
            for(var i in json){
                //判断类型
                var json_item = data.json;
                var date_type = json_item[i].type;
                var item_caption = json_item[i].caption;

                //检测是否是为时间标签
                if(date_type=='DATE'){
                    //生成时间节点
                    var date_html = '<div class="weui-cell weui-cell_vcode"><div class="weui-cell__hd"><label for="" class="weui-label"></label></div><div class="weui-cell__bd" style="height:44px;line-height:44px;"></div></div>';
                    var div_obj = $(date_html);
                    //生成左侧标题
                    div_obj.find('div:eq(0)').find('label').html(item_caption);
                    //生成右侧时间input表单
                    var createTimeValue = {
                        name:json[i].name,
                        value:json[i].value,
                        change_type:json[i].change_type
                    };
                    var time_text = createTime(createTimeValue);
                    div_obj.find('div:eq(1)').append(time_text);
                    form.find('div:eq(0)').append(div_obj);
                }else if(date_type=='VARCHAR' || date_type=='NUMBER'){
                    var text_html = '<div class="weui-cell weui-cell_vcode"><div class="weui-cell__hd"><label class="weui-label"></label></div><div class="weui-cell"><div class="weui-cell__bd"></div></div></div>';
                    //生成text节点
                    var text_obj = $(text_html);
                    //生成左侧标题
                    text_obj.find('div:eq(0)').find('label').html(item_caption);
                    //生成右侧文本input表单
                    var createTextValue = {
                        name:json[i].name,
                        value:json[i].value,
                        caption:item_caption,
                        change_type:json[i].change_type
                    };
                    var temp_text = createText(createTextValue);
                    text_obj.find('div:eq(1)').append(temp_text);
                    form.find('div:eq(0)').append(text_obj);
                }else{
                    //生成select节点
                    var select_html = '<div class="weui-cell weui-cell_vcode"><div class="weui-cell__hd"><label class="weui-label"></label></div><div class="weui-cell__hd"></div>';
                    var select_obj = $(select_html);
                    //生成左侧标题
                    select_obj.find('div:eq(0)').find('label').html(item_caption);
                    //分析字典 默认值
                    var dictionaries = json_item[i].dictionaries;
                    var select_name = json[i].name;
                    select_value = json[i].value;
                    var select_data = {
                        name:select_name,
                        dictionaries:dictionaries,
                        default_value:select_value,
                        change_type:json[i].change_type
                    };

                    var select = createSelect(select_data);
                    select_obj.find('div:eq(1)').append(select);
                    form.find('div:eq(0)').append(select_obj);
                }
            }

            //生成提交按钮 和 返回按钮
            var operation_div = $('<div class="operation_div_2"></div>');
            if(is_dealt!=1){
            	var submit = $('<input type="submit" onclick="submit(this);" class="weui-btn weui-btn_primary" value="保存">');
            }
            if(is_dealt==1){
            	var callback = $('<input type="button" class="weui-btn weui-btn_primary callback_button" value="返回">');
            }else{
				var callback = $('<input type="button" class="weui-btn weui-btn_primary callback_button" value="返回">');
            }
            if(is_dealt!=1){
            	var add = $('<input type="button" class="weui-btn weui-btn_primary add_info" value="新增">');
                var del = $('<input _offset_id='+j+' type="button" class="weui-btn weui-btn weui-btn_warn sub_del" value="删除">');
            }
            operation_div.append(submit);
            operation_div.append(callback);
            operation_div.append(add);
            operation_div.append(del);

            //添加表单隐藏域信息
            form.append($('<input type="hidden" name="table_name" value="'+data.name+'"/>'));
            form.append($('<input type="hidden" name="has_value" value="1"/>'));
            //追加当前记录位置id
            form.append($('<input type="hidden" name="_offset_id" value="'+j+'"/>'));
            form.find('div:eq(0)').append(operation_div);
            //最终生成dom节点数据
            temp.append(form);
            div2.append(temp);
        }

        var page = $('<div style="position:fixed;top:-3px;z-index:0;" class="swiper-pagination"></div>');
        //判断单条数据情况 如果单条则隐藏蓝点
        if(total!=1){
            div1.append(page);
        }
        div1.append(div2);
        $('body').append(div1);
    }
}

/**
 * 非可拓展json结构 员工基本信息
 */
function formStart(data){
    var item_name = data.name; //子集名称
    var change_item = data.change_item;//已经提交审核的子集项
    var kz_json = data.kz_json;  //扩展配置数据
	dic_list = data.dic;
    var form = createForm({action:data.action,name:data.name,method:data.method});
    var temp_id = 0;//用于拼接id
    var q=0;//用于添加页面照片id数据
    //追加表格数据
    form.append($('<div class="weui-cells weui-cells_form"></div>'));
    //获取子集数据
    var json = data.json;
    //获取对象长度
    var a = 0;
    for(var i in json){
        a++;
    }
    if(a==0){
        //这里使用weui样式
        alert('没有该子集显示项!');
        history.back(-1);
        return;
    }
    for(i in json){
        var change_type = json[i].change_type;
        if(json[i].type=='DATE'){
            //生成时间节点
            var date_html = '<div class="weui-cell weui-cell_vcode"><div class="weui-cell__hd"><label for="inputDate_'+temp_id+'" class="weui-label"></label></div><div class="weui-cell__bd" style="height:44px;line-height:44px;"></div></div>';
            var div_obj = $(date_html);
            //生成左侧标题 必填加上*
            if(kz_json[i]){
                if(kz_json[i].file){
                    var html = json[i].caption+'<font color="red">*</font>';
                }else{
                    var html = json[i].caption;
                }
            }else{
                var html = json[i].caption;
            }
            div_obj.find('div:eq(0)').find('label').html(html);
            //如果有修改,标题置为red
            if(change_type == 1){
                div_obj.find('div:eq(0)').find('label').css('color','red');
            }
            //生成右侧时间input表单
            var createTimeValue = {
                name:i,
                value:json[i].value,
                caption:json[i].caption,
                change_type :json[i].change_type
            };
            //字段是否可编辑
            if(json[i].value != ''){
                var status = 1;
            }else{
                var status = 0;
            }
            var time_text = createTime(createTimeValue,kz_json[i],temp_id,status);
            div_obj.find('div:eq(1)').append(time_text);
            form.find('div:eq(0)').append(div_obj);
            temp_id++;
        }else if(json[i].type=='LIST' || json[i].type=='LIST1'){
            //生成select节点
            var select_html = '<div class="weui-cell weui-cell_vcode"><div class="weui-cell__hd"><label class="weui-label" for="inputList_'+temp_id+'"></label></div><div class="weui-cell__hd"></div>';
            var select_obj = $(select_html);
            //生成左侧标题 必填加上*
            if(kz_json[i]){
                if(kz_json[i].file){
                    var html = json[i].caption+'<font color="red">*</font>';
                }else{
                    var html = json[i].caption;
                }
            }else{
                var html = json[i].caption;
            }
            select_obj.find('div:eq(0)').find('label').html(html);
            //如果有修改,标题置为red
            if(change_type == 1){
                select_obj.find('div:eq(0)').find('label').css('color','red');
            }
            //分析字典 默认值
            var select_data = {
                name:i,
                dictionaries:json[i].dictionaries,
                default_value:json[i].value,
                wyx : json[i].wyx
            };
            //字段是否可编辑
            if(json[i].value != ''){
                var status = 1;
            }else{
                var status = 0;
            }
            var select = createSelect(select_data,kz_json[i],temp_id,status);
            select_obj.find('div:eq(1)').append(select);
            form.find('div:eq(0)').append(select_obj);
            temp_id++;
        }else if(json[i].type == 'LAYER'){
            /**************树形字典**************/
            var layer_html = '<div class="weui-cell weui-cell_vcode"><div class="weui-cell__hd"><label class="weui-label" for="inputLayer_'+temp_id+'"></label></div><div class="weui-cell"><div class="weui-cell__bd"></div></div></div>';
            //生成layer节点
            var layer_obj = $(layer_html);
            //生成左侧标题 必填加上*
            if(kz_json[i]){
                if(kz_json[i].file){
                    var html = json[i].caption+'<font color="red">*</font>';
                }else{
                    var html = json[i].caption;
                }
            }else{
                var html = json[i].caption;
            }
            layer_obj.find('div:eq(0)').find('label').html(html);
            //如果有修改,标题置为red
            if(change_type == 1){
                layer_obj.find('div:eq(0)').find('label').css('color','red');
            }
            //生成右侧文本input表单
            var createLayerValue = {
                name:i,
                dictionaries:json[i].dictionaries,
                default_value:json[i].value,
                change_type:json[i].change_type,
                wyx : json[i].wyx
            };
            // console.log(createLayerValue)
            //字段是否可编辑
            if(json[i].value != ''){
                var status = 1;
            }else{
                var status = 0;
            }
            var layer_text = createLayer(createLayerValue,kz_json[i],temp_id,status);
            layer_obj.find('div:eq(1)').append(layer_text);

            form.find('div:eq(0)').append(layer_obj);
            temp_id++;
        }else if(json[i].type=='NUMBER'){
            var number_html = '<div class="weui-cell weui-cell_vcode"><div class="weui-cell__hd"><label class="weui-label" for="inputNumber_'+temp_id+'"></label></div><div class="weui-cell"><div class="weui-cell__bd"></div></div></div>';
            //生成text节点
            var number_obj = $(number_html);
            //生成左侧标题 必填加上*
            if(kz_json[i]){
                if(kz_json[i].file){
                    var html = json[i].caption+'<font color="red">*</font>';
                }else{
                    var html = json[i].caption;
                }
            }else{
                var html = json[i].caption;
            }
            number_obj.find('div:eq(0)').find('label').html(html);
            //如果有修改,标题置为red
            if(change_type == 1){
                number_obj.find('div:eq(0)').find('label').css('color','red');
            }
            //生成右侧文本input表单
            var createNumberValue = {
                name:i,
                value:json[i].value,
                caption:json[i].caption,
                change_type:json[i].change_type
            };
            //字段是否可编辑
            if(json[i].value != ''){
                var status = 1;
            }else{
                var status = 0;
            }
            var temp_number = createNumber(createNumberValue,kz_json[i],temp_id,status);
            number_obj.find('div:eq(1)').append(temp_number);
            form.find('div:eq(0)').append(number_obj);
            form.find('div:eq(0)').append(select_obj);
            temp_id++;
        }else if(json[i].type == 'FILE'){
            //var text_html = '<div class="weui-cell weui-cell_vcode"><div class="weui-cell__hd"><label class="weui-label" for="inputText_'+temp_id+'"></label></div><div class="weui-cell"><div class="weui-cell__bd"></div></div></div>';
            if(i != 'ZP'){
                var file_html = '<div class="weui-cell weui-cell_vcode"><div class="weui-cell__hd"><label class="weui-label  control-label" for="inputFile_'+temp_id+'"></label></div><div class="weui-cell fj"><div class="file_result">';
                for(var h in json[i].value){
                    if(json[i].value[h].status != 4){
                        file_html += '<div class="file_info"><span>'+h+'</span><span><a href="'+json[i].value[h].href+'">下载</a></span><span><a class="removefile" href="javascript:;" zd_name="'+i+'" filename="'+h+'" offset="0" onclick="remove_result(this)">删除</a></span></div>'
                    }
                }
                file_html += '</div><div class="file_warp"></div></div></div>';
            }

            //生成text节点
            var file_obj = $(file_html);
            //生成左侧标题 必填加上*
            if(kz_json[i]){
                if(kz_json[i].file){
                    var html = json[i].caption+'<font color="red">*</font>';
                }else{
                    var html = json[i].caption;
                }
            }else{
                var html = json[i].caption;
            }
            file_obj.find('div:eq(0)').find('label').html(html);
            //如果有修改,标题置为red
            if(change_type == 1){
                file_obj.find('div:eq(0)').find('label').css('color','red');
            }
            //生成右侧文本input表单
            var createFileValue = {
                name:i,
                caption:json[i].caption,
                change_type :json[i].change_type
            };
            //字段是否可编辑
            if(json[i].value != ''){
                var status = 1;
            }else{
                var status = 0;
            }
            var temp_file = createFile(createFileValue,kz_json[i],temp_id,status);
            if(i=='ZP'){
                //隐藏上传照片按钮
                file_obj.find('.zp_up').append(temp_file);
            }else{
                file_obj.find('.file_warp').append(temp_file);
            }

            form.find('div:eq(0)').append(file_obj);
            temp_id++;
        }else{
            var text_html = '<div class="weui-cell weui-cell_vcode"><div class="weui-cell__hd"><label class="weui-label" for="inputText_'+temp_id+'"></label></div><div class="weui-cell"><div class="weui-cell__bd"></div></div></div>';
            //生成text节点
            var text_obj = $(text_html);
            //生成左侧标题 必填加上*
            if(kz_json[i]){
                if(kz_json[i].file){
                    var html = json[i].caption+'<font color="red">*</font>';
                }else{
                    var html = json[i].caption;
                }
            }else{
                var html = json[i].caption;
            }
            text_obj.find('div:eq(0)').find('label').html(html);
            //如果有修改,标题置为red
            if(change_type == 1){
                text_obj.find('div:eq(0)').find('label').css('color','red');
            }
            //生成右侧文本input表单
            var createTextValue = {
                name:i,
                value:json[i].value,
                caption:json[i].caption,
                change_type :json[i].change_type
            };
            //字段是否可编辑
            if(json[i].value != ''){
                var status = 1;
            }else{
                var status = 0;
            }
            var temp_text = createText(createTextValue,kz_json[i],temp_id,status);
            text_obj.find('div:eq(1)').append(temp_text);
            form.find('div:eq(0)').append(text_obj);
            temp_id++;
        }
    }
    //生成提交按钮 和 返回按钮
    var operation_div = $('<div class="operation_div"></div>');
    if(change_item.indexOf(item_name) > -1){
        var submit = $('<input type="submit" class="weui-btn weui-btn_primary" value="员工基本信息已在审批中,不可修改,不可提交审批">');
    }else{
        var submit = $('<input type="submit" class="weui-btn weui-btn_primary" value="保存">');
    }
    var callback = $('<input type="button" class="weui-btn weui-btn_disabled weui-btn_default callback_button" value="取消操作">');
    operation_div.append(submit);
    operation_div.append(callback);
    //添加表单隐藏域信息
    form.append($('<input type="hidden" name="table_name" value="'+data.name+'"/>'));
    form.find('div:eq(0)').append(operation_div);
    //最终生成dom节点数据
    $('body').append(form);
}

/**
 * 添加新记录数据
 */
function addNew(data){
	dic_list = data.dic;
    pro_list = data.pro_dic;
    var form = createForm({action:data.action,name:data.name,method:data.method});
    //追加表格数据
    form.append($('<div class="weui-cells weui-cells_form"></div>'));
    var json = data.json;
    var length = json.length;
    //检测是否有数据
    if(length==0){
        alert('没有该子集显示项!');
        history.back(-1);
        return;
    }
    for(var i=0;i<length;i++){
        //检测是否是为时间标签
        if(json[i].type=='DATE'){
            //生成时间节点
            var date_html = '<div class="weui-cell weui-cell_vcode"><div class="weui-cell__hd"><label for="" class="weui-label"></label></div><div class="weui-cell__bd" style="height:44px;line-height:44px;"></div></div>';
            var div_obj = $(date_html);
            //生成左侧标题
            div_obj.find('div:eq(0)').find('label').html(json[i].caption);
            //生成右侧时间input表单
            var createTimeValue = {
                name:json[i].name,
                value:''
            };
            var time_text = createTime(createTimeValue);
            div_obj.find('div:eq(1)').append(time_text);
            form.find('div:eq(0)').append(div_obj);
        }else if(json[i].dictionaries==''){
            var text_html = '<div class="weui-cell weui-cell_vcode"><div class="weui-cell__hd"><label class="weui-label"></label></div><div class="weui-cell"><div class="weui-cell__bd"></div></div></div>';
            //生成text节点
            var text_obj = $(text_html);
            //生成左侧标题
            text_obj.find('div:eq(0)').find('label').html(json[i].caption);
            //生成右侧文本input表单
            var createTextValue = {
                name:json[i].name,
                value:'',
                caption:json[i].caption
            };
            var temp_text = createText(createTextValue);
            text_obj.find('div:eq(1)').append(temp_text);
            form.find('div:eq(0)').append(text_obj);
        }else{
            //生成select节点
            var select_html = '<div class="weui-cell weui-cell_vcode"><div class="weui-cell__hd"><label class="weui-label"></label></div><div class="weui-cell__hd"></div>';
            var select_obj = $(select_html);
            //生成左侧标题
            select_obj.find('div:eq(0)').find('label').html(json[i].caption);
            //分析字典 默认值
            var dictionaries = json[i].dictionaries;
            var select_data = {
                name:json[i].name,
                dictionaries:dictionaries,
            };
            var select = createSelect(select_data);
            select_obj.find('div:eq(1)').append(select);
            form.find('div:eq(0)').append(select_obj);
        }
    }
    var operation_div = $('<div class="operation_div"></div>');
    var submit = $('<input type="submit" class="weui-btn weui-btn_primary" value="提交保存">');
    var callback = $('<input type="button" class="weui-btn weui-btn_disabled weui-btn_default callback_button" value="取消操作">');
    operation_div.append(submit);
    operation_div.append(callback);

    //添加表单隐藏域信息
    form.append($('<input type="hidden" name="table_name" value="'+data.name+'"/>'));
    form.find('div:eq(0)').append(operation_div);
    //最终生成dom节点数据
    $('body').append(form);
}

/**
 * 生成form表单对象
 */
function createForm(args){
    var dom = $("<form name='"+args.name+"' action='"+args.action+"' method='"+args.method+"'></form>");
    return dom;
}

/**
 * 生成text文本表单对象
 */
function createText(data,kz_info,temp_id,status){
    var val = data.value;
    var text_input = $('<input class="weui-input" id="inputText_'+temp_id+'" type="text" placeholder="请输入'+data.caption+'"/>');
    if(kz_info){
        if(kz_info.file){
            text_input.attr({
                required:'required'
            });
        }
        if(status==1 && kz_info.modify){
            text_input.attr({
                disabled:'disabled'
            });
        }
    }
    text_input.attr({
        name:data.name,
        value:val
    });
    return text_input;
}

/*
 * 生成时间对象
 */
function createTime(data,kz_info,temp_id,status){
    if(typeof data.value =='undefined'){
        var time=data.value;
    }else{
        //截取时间长度Y-M-D
        var time=data.value.substr(0,10);
    }
    var time_input = $('<input style="padding-left:15px;" class="weui-input" type="date" id="inputDate_'+temp_id+'"/>');
    if(kz_info){
        if(kz_info.file){
            time_input.attr({
                required:'required'
            });
        }
        if(status==1 && kz_info.modify){
            time_input.attr({
                disabled:'disabled'
            });
        }
    }
    time_input.attr({
        name:data.name,
        value:time
    });
    return time_input;
}
/**
 * 生成file 文件对象
 */
function createFile(data,kz_info,temp_id,status){
    if(data.name =='ZP'){
        var file_input = $('<input class="weui-input" name="ZP[]" type="file" id="inputFile_'+temp_id+'" onchange="fileZpSize(this);"/>');
    }else{
        var file_input = $('<span><span class="file_add"><a class="clonebtn" href="javascript:;"onclick="add_file(this);" >[+]</a></span></span><input class="weui-input file_input" multiple  type="file" name="'+data.name+'[]" id="inputFile_'+temp_id+'" onchange="fileFJSize(this);"/>');
    }
    if(kz_info){
        if(kz_info.file){
            file_input.attr({
                required:'required'
            });
        }
        if(status==1 && kz_info.modify){
            file_input.attr({
                disabled:'disabled'
            });
        }
    }

    return file_input;
}
/**
 * 生成数字表单对象
 */
function createNumber(data,kz_info,temp_id,status){
    var val = data.value;
    var number_input = $('<input class="weui-input"  type="number" id="inputNumber_'+temp_id+'"  placeholder="请输入'+data.caption+'"/>');
    if(kz_info){
        if(kz_info.file){
            number_input.attr({
                required:'required'
            });
        }
        if(status==1 && kz_info.modify){
            number_input.attr({
                disabled:'disabled'
            });
        }
    }
    number_input.attr({
        name:data.name,
        value:val
    });
    return number_input;
}
/**
 * 生成下拉select对象
 */
function createSelect(data,kz_info,temp_id,status){
    if(data.wyx){
        var select_input = $('<select class="weui-select checkWyx"  id="inputList_'+temp_id+'" ></select>');
    }else{
        var select_input = $('<select class="weui-select"  id="inputList_'+temp_id+'" ></select>');
    }
    if(kz_info){
        if(kz_info.file){
            select_input.attr({
                required:'required'
            });
        }
        if(status==1 && kz_info.modify){
            select_input.attr({
                disabled:'disabled'
            });
        }
    }
    select_input.attr({
        name:data.name,
        dictionaries:data.dictionaries
    });

    //正常情况
    var dictionaries = data.dictionaries;
    var select_input = getDictionaries(dictionaries,data.default_value,select_input);
    return select_input;


}



/**
 * 获取字典下拉
 */
function getDictionaries(id,default_value,select_obj){
    //判断默认值否是为空
    var fir_option = $('<option value="">请选择</option>');

    //添加默认项节点
    select_obj.append(fir_option);
    var obj = dic_list[id];
    //console.log(obj);return;
    if(!obj){
        return select_obj;
    }
    var dic_subitem = obj.subitem;
    var tob = 0;
    for(var j=0;j<dic_subitem.length;j++){
        var option = $('<option></option>');
        //判断是否显示
        if(dic_subitem[j].display==true){
            option.attr({
                value:dic_subitem[j].caption
            });
            //默认值选中
            if(dic_subitem[j].caption==default_value){
                tob = 1;
                option.attr({
                    selected:true
                });
            }
            option.html(dic_subitem[j].caption);
            select_obj.append(option);
        }
    }
    if(tob==0 && default_value){
        select_obj.append($('<option style="display:none" value="'+default_value+'" selected>'+default_value+'</option>'));
    }
    return select_obj;
}
/**
 * 生成layer文本表单对象
 */
var layer_id = [];
function createLayer(data,kz_info,temp_id,status){
    var id = data.dictionaries;
    var item = layer_js[id];
    //console.log(item);
    var val = data.default_value;
    //取到id和对应的数据字典名称
    if(id == 'BO_CASC_HR_JCXX_JG'){
        var layer_input = $('<input class="weui-input ztree"  type="text"  id="inputLayer_'+temp_id+'" placeholder="请选择" />');
    }else{
        var layer_input = $('<input class="weui-input ztree"  type="text"  id="inputLayer_'+temp_id+'" placeholder="请选择" readonly="readonly"/>');
    }

    var temp_layer = 'inputLayer_'+temp_id;
    var temp_layer_id = id;
    layer_id[temp_layer] = temp_layer_id;
    // console.log(layer_id);
    if(kz_info){
        if(kz_info.file){
            layer_input.attr({
                required:'required'
            });
        }
        if(status==1 && kz_info.modify){
            layer_input.attr({
                disabled:'disabled'
            });
        }
    }
    // console.log(layer_js);
    layer_input.attr({
        name:data.name,
        value:val
    });
    return layer_input;
}
